from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-09-10 14:12:43.018069
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 10, Sep, 2021
Time: 14:12:48
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.0962
Nobs: 410.000 HQIC: -46.6290
Log likelihood: 4484.57 FPE: 3.96118e-21
AIC: -46.9778 Det(Omega_mle): 3.18886e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.431444 0.093267 4.626 0.000
L1.Burgenland 0.104380 0.048276 2.162 0.031
L1.Kärnten -0.114117 0.024021 -4.751 0.000
L1.Niederösterreich 0.173477 0.103705 1.673 0.094
L1.Oberösterreich 0.122976 0.101425 1.212 0.225
L1.Salzburg 0.282787 0.050599 5.589 0.000
L1.Steiermark 0.020870 0.066996 0.312 0.755
L1.Tirol 0.108757 0.052958 2.054 0.040
L1.Vorarlberg -0.112086 0.047693 -2.350 0.019
L1.Wien -0.010962 0.092548 -0.118 0.906
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.014665 0.216242 0.068 0.946
L1.Burgenland -0.046190 0.111928 -0.413 0.680
L1.Kärnten 0.037541 0.055693 0.674 0.500
L1.Niederösterreich -0.214032 0.240441 -0.890 0.373
L1.Oberösterreich 0.489509 0.235156 2.082 0.037
L1.Salzburg 0.304441 0.117316 2.595 0.009
L1.Steiermark 0.112569 0.155331 0.725 0.469
L1.Tirol 0.314912 0.122783 2.565 0.010
L1.Vorarlberg 0.001220 0.110576 0.011 0.991
L1.Wien -0.003010 0.214574 -0.014 0.989
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.251697 0.047546 5.294 0.000
L1.Burgenland 0.090802 0.024610 3.690 0.000
L1.Kärnten -0.001648 0.012245 -0.135 0.893
L1.Niederösterreich 0.206591 0.052866 3.908 0.000
L1.Oberösterreich 0.169839 0.051704 3.285 0.001
L1.Salzburg 0.033778 0.025794 1.309 0.190
L1.Steiermark 0.018204 0.034153 0.533 0.594
L1.Tirol 0.067822 0.026997 2.512 0.012
L1.Vorarlberg 0.059719 0.024313 2.456 0.014
L1.Wien 0.104812 0.047179 2.222 0.026
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.179558 0.046513 3.860 0.000
L1.Burgenland 0.048907 0.024075 2.031 0.042
L1.Kärnten -0.006736 0.011979 -0.562 0.574
L1.Niederösterreich 0.137904 0.051718 2.666 0.008
L1.Oberösterreich 0.318115 0.050581 6.289 0.000
L1.Salzburg 0.099814 0.025234 3.956 0.000
L1.Steiermark 0.132093 0.033411 3.954 0.000
L1.Tirol 0.075513 0.026410 2.859 0.004
L1.Vorarlberg 0.056479 0.023784 2.375 0.018
L1.Wien -0.041856 0.046154 -0.907 0.364
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.210920 0.092395 2.283 0.022
L1.Burgenland -0.055874 0.047824 -1.168 0.243
L1.Kärnten -0.034712 0.023796 -1.459 0.145
L1.Niederösterreich 0.115449 0.102734 1.124 0.261
L1.Oberösterreich 0.167829 0.100476 1.670 0.095
L1.Salzburg 0.257586 0.050126 5.139 0.000
L1.Steiermark 0.079273 0.066369 1.194 0.232
L1.Tirol 0.123742 0.052462 2.359 0.018
L1.Vorarlberg 0.116981 0.047246 2.476 0.013
L1.Wien 0.023146 0.091682 0.252 0.801
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.027877 0.071719 0.389 0.697
L1.Burgenland 0.024801 0.037122 0.668 0.504
L1.Kärnten 0.052223 0.018471 2.827 0.005
L1.Niederösterreich 0.212157 0.079745 2.660 0.008
L1.Oberösterreich 0.334315 0.077992 4.287 0.000
L1.Salzburg 0.045301 0.038909 1.164 0.244
L1.Steiermark -0.005319 0.051517 -0.103 0.918
L1.Tirol 0.112970 0.040723 2.774 0.006
L1.Vorarlberg 0.066775 0.036674 1.821 0.069
L1.Wien 0.129688 0.071166 1.822 0.068
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185376 0.087718 2.113 0.035
L1.Burgenland 0.019635 0.045403 0.432 0.665
L1.Kärnten -0.057570 0.022592 -2.548 0.011
L1.Niederösterreich -0.113062 0.097534 -1.159 0.246
L1.Oberösterreich 0.188831 0.095390 1.980 0.048
L1.Salzburg 0.029448 0.047588 0.619 0.536
L1.Steiermark 0.299869 0.063009 4.759 0.000
L1.Tirol 0.487025 0.049806 9.778 0.000
L1.Vorarlberg 0.069067 0.044855 1.540 0.124
L1.Wien -0.105679 0.087041 -1.214 0.225
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.163262 0.095304 1.713 0.087
L1.Burgenland -0.006462 0.049330 -0.131 0.896
L1.Kärnten 0.062227 0.024545 2.535 0.011
L1.Niederösterreich 0.184838 0.105969 1.744 0.081
L1.Oberösterreich -0.129111 0.103640 -1.246 0.213
L1.Salzburg 0.238189 0.051704 4.607 0.000
L1.Steiermark 0.158590 0.068459 2.317 0.021
L1.Tirol 0.051154 0.054114 0.945 0.345
L1.Vorarlberg 0.127928 0.048734 2.625 0.009
L1.Wien 0.151863 0.094569 1.606 0.108
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.486699 0.051684 9.417 0.000
L1.Burgenland -0.010500 0.026752 -0.392 0.695
L1.Kärnten -0.009729 0.013311 -0.731 0.465
L1.Niederösterreich 0.208543 0.057467 3.629 0.000
L1.Oberösterreich 0.261591 0.056204 4.654 0.000
L1.Salzburg 0.023335 0.028039 0.832 0.405
L1.Steiermark -0.025888 0.037125 -0.697 0.486
L1.Tirol 0.066587 0.029346 2.269 0.023
L1.Vorarlberg 0.057245 0.026429 2.166 0.030
L1.Wien -0.054711 0.051285 -1.067 0.286
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.020366 0.079648 0.137764 0.135828 0.040396 0.072124 -0.001288 0.174270
Kärnten 0.020366 1.000000 -0.045378 0.126628 0.047138 0.070372 0.455663 -0.094129 0.092222
Niederösterreich 0.079648 -0.045378 1.000000 0.286342 0.082120 0.267576 0.022006 0.139423 0.260480
Oberösterreich 0.137764 0.126628 0.286342 1.000000 0.182917 0.285860 0.155763 0.102363 0.139316
Salzburg 0.135828 0.047138 0.082120 0.182917 1.000000 0.126356 0.056986 0.102891 0.049206
Steiermark 0.040396 0.070372 0.267576 0.285860 0.126356 1.000000 0.130906 0.087884 -0.024623
Tirol 0.072124 0.455663 0.022006 0.155763 0.056986 0.130906 1.000000 0.040476 0.116688
Vorarlberg -0.001288 -0.094129 0.139423 0.102363 0.102891 0.087884 0.040476 1.000000 -0.048769
Wien 0.174270 0.092222 0.260480 0.139316 0.049206 -0.024623 0.116688 -0.048769 1.000000